/**
 *选择sku
 */
var attrsetid = 0;//属性集id，选择分类的时候赋值，product_input_category.js中getCategories方法赋值
var allSkus = {};
var selSkusMap = null;//编辑商品信息时用
var fieldsetId = "skus";
var skuoptId = "skuopt";
var skuMap = null;
var skuNames = null;//保存sku可选项名称
var productSkuMapCopy = null;//sku组合，提交数据用
var productSkuMap = null;//sku组合，页面显示用
var ProductSku = function(){
  this.barcode = "";
  this.cur_price = 0;
  //this.enabled = true;
  //this.productid = "";
  //this.product_sku_code = "";  
  this.model_code = "";
  this.sku_opt_id = "";  
  //this.status = 0;//上架状态，默认为0：待审核
};
/*
  把数据保存在全局变量allSkus中
*/
var saveSkuList = function(skuList){
  var len = skuList.length;
  for(var i = 0;i < len;i++){
    var sku = skuList[i];
    console.log('sku='+sku);
    allSkus[sku.skuid] = sku;
  }
};


var optMe = function(){
	var arr = [];
	$('.opt:input').each(function(){
		if($(this).prop("checked")){
			arr.push($(this).prop("name"));
		}
	});	
	$("#skuOptions").val(arr.toString());
}




/**
 *创建已经选中的skuopt对应的html元素 
 */
var setSkuOpts = function(skus){
  var opts = skus.opts;
  if(opts){
    var len = opts.length;
    if(len > 0){
      for(var i=0;i<len;i++){
        var opt = opts[i];
        var optHtml = "";
        if(opt.code=="contract" || opt.code=="bare"){
        	optHtml = "<label class=\"am-checkbox-inline\" onClick=\"optMe()\"    name='asd'>"
                + "<input type=\"checkbox\" class='opt' id=\""+skuoptId+"-"+skus.skuid+"-"+opt.id+"\" value=\""+opt.id+"\" name=\""+opt.code+"\"/>"
                +"<span>"+opt.name+"</span>"
                + "</label>";
        }else{
        	optHtml = "<label class=\"am-checkbox-inline\">"
        		+ "<input type=\"checkbox\" id=\""+skuoptId+"-"+skus.skuid+"-"+opt.id+"\" value=\""+opt.id+"\"/>"
        		+"<span>"+opt.name+"</span>"
        		+ "</label>";
        }
        
        $("#"+fieldsetId+skus.skuid).append(optHtml);
        //编辑商品信息时使用，让已选sku为已选状态
        if(selSkusMap != null){
          var selSku = selSkusMap.get(skus.skuid);
          if(selSku){
            var selopts = selSku.opt;
            var seloptslen = selopts.length;
            for(var j=0;j<seloptslen;j++){
              var selopt = selopts[j];
              if(selopt.id == opt.id){
                $("#"+skuoptId+"-"+skus.skuid+"-"+opt.id).attr("checked","checked");
              }
            }
            if(skuMap == null){
              skuMap = new Map();
            }
            skuMap.put(skus.skuid,selopts);
          }
          //编辑初始化后不可修改值
          $("#"+skuoptId+"-"+skus.skuid+"-"+opt.id).attr("disabled","disabled");
        }
      }
    }else{
      $("#"+fieldsetId+skus.skuid).remove();
    }
  }
};

/**
 * 创建用于保存已选的sku选项值的map
 * @param skus
 * @returns
 */
var createSkuMap = function(skus){
  if(skuMap == null){
    skuMap = new Map();
  }
  
  if(skus.opts.length > 0){
    if(skuNames == null)
      skuNames = new Array();
    skuNames.push(skus.skuname);
    if(!skuMap.get(skus.skuid)){
      skuMap.put(skus.skuid,new Array());
    }
  }
};

/**
 *创建已经选中属性对应的可选项html元素 
 */
var createOpts = function(skuid){
  var skus = allSkus[skuid];
  if($("#skudiv").find("#"+fieldsetId+skus.skuid).length <= 0){
      //var fieldsetHtml = $("<fieldset id=\""+fieldsetId+skus.skuid+"\" style=\"padding-bottom:20px;\"><div>"+skus.skuname+"：</div></fieldset>");
      var fieldsetHtml = $("<div class=\"am-g am-form-group am-margin-top\"><div class=\"am-u-sm-4 am-u-md-2 am-text-right\">"+skus.skuname+"：</div><div class=\"am-u-sm-6 am-u-md-6\" id=\""+fieldsetId+skus.skuid+"\"></div><div class=\"am-u-sm-2 am-u-md-4 input-msg\"></div></div>");
      fieldsetHtml.appendTo($("#skudiv"));
      setSkuOpts(skus);
      createSkuMap(skus);
  }
};

/**
 * 组合sku选项
 * @param doubleArrays
 * @returns
 */
var toComposeArray = function(doubleArrays){
  var len = doubleArrays.length;
    if (len >= 2) {
        var arr1 = doubleArrays[0];
        var arr2 = doubleArrays[1];
        var len1 = doubleArrays[0].length;
        var len2 = doubleArrays[1].length;
        var newlen = len1 * len2;
        var temp = new Array(newlen);
        var index = 0;
        for (var i = 0; i < len1; i++) {
            for (var j = 0; j < len2; j++) {
              var newid = arr1[i].id + Constant.SEPARATOR + arr2[j].id;
              var newname = arr1[i].name + Constant.SEPARATOR + arr2[j].name;
              var newObj = {"id":newid,"name":newname};
              temp[index] = newObj;
                index++;
            }
        }
        var newArray = new Array(len - 1);
        newArray[0] = temp;
        if (len > 2) {
            var _count = 1;
            for (var i = 2; i < len; i++) {
                newArray[_count] = doubleArrays[i];
                _count++;
            }
        }
        return toComposeArray(newArray);
    }
    else {
        return doubleArrays[0];
    }
};

/**
 * 获取sku可选项数据组合
 * @returns
 */
var getComposeArray = function(){
  var entrys = skuMap.entrys();
  var size = entrys.length;

  if(size > 0){
    var flag = true;
    for(var i = 0;i < size;i++){
      if(entrys[i].value.length == 0){
        if($("#skualert").length > 0){
          $("#skualert").show();
        }else{
          var alertnode = "<div id=\"skualert\" class=\"am-g am-form-group am-margin-top\">"
                        +"<div class=\"am-u-sm-4 am-u-md-2 am-text-right\">&nbsp;</div>"
                        +"<div class=\"am-u-sm-6 am-u-md-6 am-padding-vertical-xs alert-msg-warning-style am-text-xs\">注：每一项已选sku至少选中一个可选项后才可创建商品规格集！"
                        +"</div>"
                        +"<div class=\"am-u-sm-2 am-u-md-4 input-msg\"></div>"
                        +"</div>";
          // var alertnode = "<div class=\"am-padding-vertical-xs alert-msg-warning-style am-text-xs\" id=\"skualert\">"
          //     +"每一项已选sku至少选中一个可选项后才可创建商品规格集！</div>";
          $("#alertdiv").append(alertnode);
        }
        //清空
        productSkuMapCopy = null;
        flag = false;
        break;
      }
    }
    if(flag){
      var skuArrays = new Array();
      for(var i = 0;i < size;i++){
        skuArrays.push(entrys[i].value);
      }
      return toComposeArray(skuArrays);
    }
  }
};

/**
 * 创建表头
 * @returns
 */
var createTableHead = function(){
  var table = $("<table id=\"skutable\" class=\"am-table am-table-bordered\"></table>");
  table.appendTo($("#tablediv"));
  var thead = $("<thead></thead>");
  thead.appendTo(table);
  var theadTr = $("<tr></tr>");
  theadTr.appendTo(thead);
  
    $.each(skuNames, function (index, item) {
        var th = $("<th>" + item + "</th>");
        th.appendTo(theadTr);
    });
    
    var itemColumHead = $("<th>价格<span style=\"color:red;\">&nbsp;*</span></th><th>机型代码</th>");
    itemColumHead.appendTo(theadTr);

    var tbody = $("<tbody></tbody>");
    tbody.appendTo(table);
    
    return tbody;
};

/**
 * 创建表格
 * @returns
 */
var createTable = function(composeArrays){
  //创建表头
  var tbody = createTableHead();
  if(productSkuMap == null)
    productSkuMap = new Map();

  productSkuMapCopy = new Map();

  //创建行
  $.each(composeArrays, function (index, item) {
    var nameArr = item.name.split(Constant.SEPARATOR);
    var tr = $("<tr></tr>");
    tr.appendTo(tbody);

    //创建列
    $.each(nameArr, function (i, values) {
      var td = $("<td>" + values + "</td>");
      td.appendTo(tr);
    });

    //获取opt组合id，并排序，与后台取得的数据保持一致
    var optIdArr = item.id.toString().split(Constant.SEPARATOR);
    optIdArr.sort(function (a,b){
        return a - b;
    });
    var optids = optIdArr.join(Constant.SEPARATOR);

    var cur_price = $("#cur_price").val();
    var psku = productSkuMap.get(optids);
    if(!psku){
      psku = new ProductSku();
      psku.sku_opt_id = optids;
      psku.cur_price = cur_price ? cur_price : 0;
      psku.model_code = "";

      productSkuMap.put(optids,psku);
    }

    productSkuMapCopy.put(optids,psku);

    var td1 = $("<td><input class=\"am-form-field am-input-sm skuprice\" id=\"price-"+optids+"\" type=\"text\" value=\""+psku.cur_price+"\" required placeholder=\"价格\"/></td>");
    td1.appendTo(tr);
    var td2 = $("<td><input class=\"am-form-field am-input-sm skumodecode\" id=\"model_code-"+optids+"\" type=\"text\" value=\""+psku.model_code+"\" placeholder=\"机型代码\"/></td>");
    td2.appendTo(tr);
  });
};


/**
 * 验证价格
 * @param priceObj
 * @returns
 */
var validPrice = function(priceObj,tagname){
  var regex = /^([1-9]\d{0,10}|0)(\.\d{1,2})?$/;//小数点前面最多9位数字，小数点后面最多2位数字，可以没有小数
  var regex1 = /^[0-9]*[0-9][0-9]*$/;//正整数
  var re = new RegExp(regex);
  var re1 = new RegExp(regex1);
    var price = priceObj.val();
    //data-am-popover=\"{theme: 'danger sm', content: '点击显示的 Danger & Small'}\"
    if (!price.match(re1)) {
      // if(price == 0){
      //   //priceObj.attr("data-original-title","价格只能是正整数或者正浮点数！");
      //   //priceObj.attr("data-am-popover","{theme: 'danger sm', content: '价格只能是正整数或者正浮点数！'}");
      //   priceObj.popover({
      //     content: '价格只能是正整数或者正浮点数！'
      //   });
      //   priceObj.val("1");

      //   //priceObj.tooltip("show");
      //   priceObj.popover('open');
      // }
      if (!price.match(re)) {
          var pricearray = price.split(".");
          var price2 = pricearray[1];

          // var content = "";
          // priceObj.popover({
          //   content: content,
          //   theme: 'danger sm',
          //   trigger: 'focus'
          // });

          //priceObj.popover('open');

          if(!isNaN(price) && price > 0 && price2 && price2.length > 2){
            //priceObj.attr("data-original-title","价格小数点后只能保留两位数字！");
            //priceObj.attr("data-am-popover","{theme: 'danger sm', content: '价格小数点后只能保留两位数字！'}");

              priceObj.popover({
                content: tagname + '只能保留两位小数！',
                theme: 'danger sm',
                trigger: 'focus'
              });

              priceObj.popover('open'); 

              // if($(".am-popover").hasClass("am-active")){
              //   $(".am-popover-inner").html("价格只能保留两位小数！");
              // }
            content = tagname + "只能保留两位小数！";
            priceObj.val(pricearray[0] + "." + price2.substr(0,2));
          }else{
            //priceObj.attr("data-original-title","价格只能是正整数或者正浮点数！");
            //priceObj.attr("data-am-popover","{theme: 'danger sm', content: '价格只能是正整数或者正浮点数！'}");
            
              priceObj.popover({
                content: tagname + '只能是零、正整数或者正浮点数！',
                theme: 'danger sm',
                trigger: 'focus'
              });

              priceObj.popover('open');

              // if($(".am-popover").hasClass("am-active")){
              //   $(".am-popover-inner").html("价格只能是零、正整数或者正浮点数！");
              // }

            content = tagname + "只能是零、正整数或者正浮点数！";
            priceObj.val("0");
          }
          
          priceObj.popover('setContent', content);
          //priceObj.tooltip("show");
          //priceObj.popover('open');
      }
    }
};

/**
 * 为商品规格编辑按钮绑定点击事件
 * @returns
 */
var bindEditSkuBtn = function(){
  $.each($("#skudiv").find("input[type='checkbox']"),function(){
    $(this).removeAttr("disabled");
  });
  $.each($("#tablediv").find("table").find("input[type='text']"),function(){
    $(this).removeAttr("disabled");
  });
  $("#sourceMultiSelect").removeAttr("disabled");
  $("#destMultiSelect").removeAttr("disabled");
};

/**
 * 创建商品规格编辑按钮
 * @returns
 */
var createEditSkuBtn = function(){
  // var btnnode = "<div id=\"editSkuBtn\" class=\"control-group\">"
  //               + "<button class=\"btn btn-primary\" id=\"editSku\">修改商品规格</button>"
  //               + "<span id=\"editSkuBtnMsg\" class=\"alert alert-info\" style=\"margin-left:5px;\">"
  //               + "需要修改商品规格请点击此按钮，不需要修改则不用点击！"
  //               + "</span>"
  //               + "</div>";
  var btnnode = "<div id=\"editSkuBtn\" class=\"am-g am-form-group am-margin-top\">"
                +"<div class=\"am-u-sm-4 am-u-md-2 am-text-right\">"
                +"<button type=\"button\" class=\"am-btn am-btn-primary am-text-xs\" id=\"editSku\">修改商品规格</button>"
                +"</div>"
                +"<div class=\"am-u-sm-6 am-u-md-6 am-padding-vertical-xs alert-msg-primary-style am-text-xs\" id=\"editSkuBtnMsg\">注：需要修改商品规格请点击此按钮，不需要修改则不用点击！"
                +"</div>"
                +"<div class=\"am-u-sm-2 am-u-md-4 input-msg\"></div>"
                +"</div>";
  $("#alertdiv").append(btnnode);
  
  $("#editSku").click(function(){
    $("#is-sku-modified").val("1");
    bindEditSkuBtn();
    $(this).hide();
    $(this).parent().html("&nbsp;");
    $("#editSkuBtnMsg").html("已经处于编辑状态");
    setTimeout(function() {
      $("#editSkuBtn").addClass("am-hide");    
    },2000);
    selSkusMap = null;
  });
};

var setProductSku = function(){
  var pskuArray = new Array();
  if(productSkuMapCopy != null){
    var entrys = productSkuMapCopy.entrys();
    var size = entrys.length;
    if(size > 0){
      for(var i = 0;i < size;i++){
        var psku = productSkuMapCopy.get(entrys[i].key);
        if(psku != null){
          pskuArray.push(psku);
        }
      }
    }else{//默认商品sku
      var psku =  new ProductSku();
      psku.sku_opt_id = Constant.DEFAULTSKUOPTID;
      pskuArray.push(psku);
    }
  }else{//默认商品sku
    var psku =  new ProductSku();
    psku.sku_opt_id = Constant.DEFAULTSKUOPTID;
    pskuArray.push(psku);
  }
  
  $("#product-sku-array").val(JSON.stringify(pskuArray));
  //console.log(JSON.stringify(pskuArray));
  //return pskuArray;
};

/**
 * 为输入内容绑定事件，价格、库存等
 * @returns
 */
var bindInputs = function(){
  $.each($(".skuprice"),function(){
    $(this).blur(function(){
      validPrice($(this),"现价");
      
      var optids = $(this).attr("id").split("-");
      productSkuMap.get(optids[1]).cur_price = $(this).val();
      productSkuMapCopy.get(optids[1]).cur_price = $(this).val();

      //setProductSku();
    });
  });
  
  $.each($(".skumodecode"),function(){
    $(this).blur(function(){
      var optids = $(this).attr("id").split("-");
      productSkuMap.get(optids[1]).model_code = $(this).val();
      productSkuMapCopy.get(optids[1]).model_code = $(this).val();
    });
  });
};

/**
 * 根据选择的sku选项创建表格
 * @returns
 */
var createSkuTable = function(){
  //删除所有工具提示标签
  // $(".tooltip").remove();
  $(".am-popover").remove();
  
  if($("#skualert").length > 0){
    $("#skualert").hide();
  }
  if($("#alertdiv").find("#editSkuBtn").length > 0){//点击按钮后删除编辑按钮
    $("#editSkuBtn").remove();
  }
  if($("#tablediv").find("#skutable").length > 0){
    $("#tablediv").find("#skutable").remove();
  }
  //创建商品规格编辑按钮
  if(selSkusMap != null){
    createEditSkuBtn();
  }
  
  var composeArrays = getComposeArray();
  if(composeArrays && composeArrays.length > 0){
    //创建表格
    createTable(composeArrays);
    $.each($("#tablediv").find("table").find("input[type='text']"),function(){
      //编辑初始化后不可修改值
      if(selSkusMap != null)
        $(this).attr("disabled","disabled");

      $(this).focus(function(){
        //删除所有工具提示标签
        //$(".tooltip").remove();
        //$(".am-popover").remove();
        //$(this).popover('close');
        $(".am-popover").removeClass("am-active");
      });
    });
    
    //为输入内容绑定事件，价格、库存等
    bindInputs();
  }
};

/**
 * 为所创建的sku可选项绑定事件
 */
var bindOptEvent = function(skuid){
  $.each($("#skudiv").find("#"+fieldsetId+skuid).find("input[type='checkbox']"),function(){
    $(this).click(function(){
      var myid = $(this).attr("id");
      if(!myid){
        alert("opt id is null");
        return false;
      }
      var myidArray = myid.split("-");
      var myskuid = myidArray[1];
      var myopt = {"id":$(this).val(),"name":$(this).next().html()};
      
      if($(this).is(":checked")){
        skuMap.get(myskuid).push(myopt);
      }else{
        skuMap.get(myskuid).remove(myopt);
      }
      
      //初始化数据后清空
      if(selSkusMap != null)
        selSkusMap = null;
      
      createSkuTable();
    });
  });
  
  //编辑商品信息时使用，加载页面就根据已选项创建表格
  if(selSkusMap != null){
    createSkuTable();
  }
};

/**
 *显示已经选中的属性对应的可选项 
 * optionObjs：已经选中的属性
 */
var showOpts = function(optionObjs){
  var len = optionObjs.length;
  for(var i=0;i<len;i++){
    var optionObj = optionObjs[i];
    var skuid = optionObj.value;
    createOpts(skuid);
    
    bindOptEvent(skuid);//为所创建的sku可选项绑定事件
  }
  
  //setSkuDivStyle();
  
  createSkuTable();
};

var removeOpts = function(skuid){
  if($("#skus"+skuid) && $("#skus"+skuid).length > 0){
    $("#skus"+skuid).parent().remove();
  }
};

var hideOpts = function(optionObjs){
  var len = optionObjs.length;
  for(var i=0;i<len;i++){
    var optionObj = optionObjs[i];
    var skuid = optionObj.value;
    var skuname = optionObj.text;
    removeOpts(skuid);
    
    skuMap.remove(skuid);//删除被移除的sku属性和可选项数据
    skuNames.removekey(skuname);//删除被移除的表头数据（已选sku属性值）
  }
  
  //setSkuDivStyle();
  
  createSkuTable();

  //没有选中任何sku的情况下，清空内存
  if($('#destMultiSelect option').length <= 0){
    productSkuMapCopy = null;
  }
};

/*
构造sku选择项
*/
var initSourceMultiSelect = function(data){
  $("#sourceMultiSelect").empty();
  $("#destMultiSelect").empty();
  
    for(var i = 0; i < data.length; i++){
      var skuname = data[i].skuname;
      var skuid = data[i].skuid;
      var flag = true;
      if(selSkusMap != null){//判断是否有已选sku属性
        var entrys = selSkusMap.entrys();
        var size = entrys.length;
        if(size > 0){
          for(var j = 0; j < size; j++){
            var selSku = entrys[j].value;
            if(selSku.skuid == skuid){
              flag = false;
              break;
            }
          }
        }
      }
      if(flag){
        document.getElementById("sourceMultiSelect").options.add(new Option(skuname, skuid));  //name, value
      }else{//编辑时把已选sku值放在已选sku栏
        document.getElementById("destMultiSelect").options.add(new Option(skuname, skuid));  //name, value
      }
    }
    
    //编辑时初始化sku已选项
    if(selSkusMap != null){
      $("#sourceMultiSelect").attr("disabled","disabled");
      $("#destMultiSelect").attr("disabled","disabled");
      var $allOptions = $('#destMultiSelect option');  
      showOpts($allOptions);
    }

    $('#sourceMultiSelect option').addClass("am-text-xs");
    $('#destMultiSelect option').addClass("am-text-xs");
};

var showSkus = function(skuList){
  if(skuList){
    var len = skuList.length;
    if(len > 0){
      //保存数据以供动态创建sku属性和可选项
      saveSkuList(skuList);
      
      // 构造sku选择项
      initSourceMultiSelect(skuList);
    }
  }
};

var loadSkuSet = function(){
  var option = {
    attrsetid : attrsetid
  };
  $.ajax({
    url : base + "/sku/getskuinfo",
    dataType : "json",
    type : "post",
    data : option,
    success : function(data){
      console.log(data);
      showSkus(data);
    },
    error : function(msg) { // 若Ajax处理失败后回调函数，msg是返回的错误信息
      console.log(msg);
    }
  });
};

/*
  设置sku页面所属品牌项
*/
var setSelCategoryToSkuPage = function(){
  var cates = "";
  $("#breadcrumb li").each(function(i){
    if($(this).find("span").length > 0){
      $(this).children("span").remove();
    }

    cates += $(this).html();

    if(i != $("#breadcrumb").find("li").length-1){
      cates += "  >  ";
    }
  });

  $("#selected-categories").html(cates);
};

/**
 * 商品统一价格同步到内存变量
 * @param priceid
 * @param curPrice
 * @returns
 */
var setPriceToProductSkuMap = function(priceid,curPrice){
  if(productSkuMap != null){
    var psku = productSkuMap.get(priceid);
    psku.cur_price = curPrice;
    productSkuMap.put(priceid,psku);
  }
  if(productSkuMapCopy != null){
    var psku = productSkuMapCopy.get(priceid);
    psku.cur_price = curPrice;
    productSkuMapCopy.put(priceid,psku);
  }
};

/**
 * 统一价格变动后sku价格也一起变动
 * @param curPrice
 * @returns
 */
var setAllSkuPrice = function(curPrice){
  if(!curPrice)
    curPrice = 0;
  $.each($("#tablediv").find("table").find("input[type='text']"),function(){
    var priceid = $(this).attr("id").split("-");
    if(priceid[0] == "price"){
      $(this).val(curPrice);
      
      setPriceToProductSkuMap(priceid[1],curPrice);
    };
  });
};

//编辑初始化数据 begin
/**
 * 把所有已选sku可选项存到内存
 * 
 * @param selskus
 * @returns
 */
var setSelSkus = function(selskus){
  if(selSkusMap == null)
    selSkusMap = new Map();
  
  var sellen = selskus.length;
  for(var i=0;i<sellen;i++){
    var selsku = selskus[i];
    selSkusMap.put(selsku.skuid,selsku);
  }
};

/**
 * 商品sku已选项串排序
 * @param k
 * @returns
 */
var getKStr = function(k){
  var kArr = k.split(Constant.SEPARATOR);
  kArr.sort(function(v1,v2){
    return v1 - v2;
  });
  
  return kArr.join(Constant.SEPARATOR);
};

/**
 * 把所有已选sku_opt组合存到内存
 * 
 * @returns
 */
var setSelSkuOpts = function(selskuopts){
  //alert(JSON.stringify(selskuopts));
  for(var k in selskuopts){
    var psku = new ProductSku();
    psku.cur_price = selskuopts[k].cur_price;
    //psku.productid = selskuopts[k].productid;    
    psku.model_code = selskuopts[k].model_code;
    psku.barcode = selskuopts[k].barcode;
    psku.sku_opt_id = selskuopts[k].sku_opt_id;

    if(productSkuMap == null)
      productSkuMap = new Map();

    var kStr = getKStr(k);//重新排序后的sku已选项串
    productSkuMap.put(kStr,psku);
  }
  //alert(JSON.stringify(productSkuMap));
};
//编辑初始化数据 end

$(function(){  
  $('#addSku').click(function(){ 
    var $options = $('#sourceMultiSelect option:selected');//获取当前选中的项  
    var $remove = $options.remove();//删除下拉列表中选中的项  
    $remove.appendTo('#destMultiSelect');//追加给对方  
    
    showOpts($remove);
  });  
    
  $('#removeSku').click(function(){  
    var $removeOptions = $('#destMultiSelect option:selected');  
    $removeOptions.appendTo('#sourceMultiSelect');//删除和追加可以用appendTo()直接完成  
    
    hideOpts($removeOptions);
  });  
    
  //双击事件  
  $('#sourceMultiSelect').dblclick(function(){  
    var $options = $('option:selected', this);//注意此处“option”与“:”之间的空格，有空格是不可以的  
    $options.appendTo('#destMultiSelect'); 
    
    showOpts($options);
  });  
    
  $('#destMultiSelect').dblclick(function(){  
    var $removeOptions = $('#destMultiSelect option:selected');  
    $removeOptions.appendTo('#sourceMultiSelect');  
    
    hideOpts($removeOptions);
  });

  $("#cur_price").blur(function(){
    var curPrice = $(this).val();
    setAllSkuPrice(curPrice);
  });
});
